package org.jiamandan.com.strategy;

import io.netty.channel.Channel;
import io.netty.channel.ChannelId;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.jiamandan.com.cache.CacheNames;
import org.jiamandan.com.config.TcpInboundAdapter;
import org.jiamandan.com.dto.OrderDto;
import org.jiamandan.com.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

@Data
@Slf4j
public abstract class IChargeBaseService {

    @Autowired
    private RedisUtil redisUtil;

    public void execute(OrderDto dto) throws Exception {
        Map<String, ChannelId> channels = (Map<String, ChannelId> ) redisUtil.get(CacheNames.TCP_CHANNEL);
        if (channels == null) {
            log.info("充电桩未连接");
        }
        Channel channel = TcpInboundAdapter.clients.find(channels.get(dto.getPileNo()));
        issueCharge(dto,channel);
    }

    public void createOrder(){
        log.info("创建订单");
    }

    private static String switchSiteStatus(int value) {
        switch (value) {
            case 0:
                return "待运营";
            case 1:
                return "建设中";
            case 2:
                return "关闭下线";
            case 3:
                return "维护中";
            case 4:
                return "休息中";
            default:
                return "联系管理员";
        }
    }

    public abstract void issueCharge(OrderDto dto,Channel channel) throws Exception;
}
